include "unistd.h";
include "sys/time.h";

/**
 * Sleep for the specified amount of time, in seconds.
 */
function sleep(t: Double) {
    static if defined _POSIX_SOURCE {
        usleep(floor(t * 1000000) as Uint);
    } else {
        if t >= 1 {
            sleep(t as Int);
        }
    }
}

/**
 * Returns the current time, in seconds since epoch, using gettimeofday.
 */
function time(): Double {
    var tv: timeval;
    gettimeofday(&tv, null);
    return tv.tv_sec + (tv.tv_usec / 1000000.0_f64);
}
